package com.symaster.common.swing.dialog.setting.item;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.symaster.common.swing.element.list.SwingListAbs;
import com.symaster.common.swing.style.Style;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @author MGZC
 * @time 2021/8/26 21:25
 */
public class SettingItem extends SwingListAbs {

    // 已选择背景
    private static final Color select_color = new Color(38, 42, 46);
    // 未选择背景
    private static final Color not_select_color = new Color(30, 34, 38);
    private final String name;
    private JPanel root;
    private JTextField name_text_field;
    private JPanel p1;
    private JPanel abdai;

    public SettingItem(String uuid, String name) {
        super(uuid);
        this.name = name;
        setLayout(new BorderLayout(0, 0));
        initFont();
        initBorder();
        initText();
        initListener();
        this.add(root);
        setVisible(true);
        root.setVisible(true);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("SettingItem");
        frame.setContentPane(new SettingItem("aisdasagasdfasdfa", "Hello World").root);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    private void initListener() {
        p1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                select();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        name_text_field.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                select();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
    }

    @Override
    public void selectListener() {
        p1.setBackground(select_color);
        name_text_field.setBackground(select_color);
        abdai.setVisible(true);
        repaint();
    }

    @Override
    public void oldSelectListener() {
        p1.setBackground(not_select_color);
        name_text_field.setBackground(not_select_color);
        abdai.setVisible(false);
        repaint();
    }

    public String getMyName() {
        return name;
    }

    private void initText() {
        name_text_field.setText(this.name);
    }

    private void initFont() {
        Style.setFont(1, name_text_field);
    }

    private void initBorder() {
        Style.setBorder(Style.BORDER_EMPTY, name_text_field);
    }

    @Override
    public void setPreferredSize(Dimension preferredSize) {
        super.setPreferredSize(preferredSize);
        root.setPreferredSize(preferredSize);
    }

    {
        // GUI initializer generated by IntelliJ IDEA GUI Designer
        // >>> IMPORTANT!! <<<
        // DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        root = new JPanel();
        root.setLayout(new BorderLayout(0, 0));
        root.setBackground(new Color(-14802394));
        root.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new BorderLayout(0, 0));
        panel1.setBackground(new Color(-14802394));
        panel1.setPreferredSize(new Dimension(6, 0));
        root.add(panel1, BorderLayout.WEST);
        abdai = new JPanel();
        abdai.setLayout(new BorderLayout(0, 0));
        abdai.setBackground(new Color(-425364));
        abdai.setPreferredSize(new Dimension(2, 0));
        abdai.setVisible(false);
        panel1.add(abdai, BorderLayout.EAST);
        p1 = new JPanel();
        p1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        p1.setBackground(new Color(-14802394));
        root.add(p1, BorderLayout.CENTER);
        p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        name_text_field = new JTextField();
        name_text_field.setBackground(new Color(-14802394));
        name_text_field.setDisabledTextColor(new Color(-6511186));
        name_text_field.setEditable(false);
        name_text_field.setEnabled(false);
        p1.add(name_text_field, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    }

    /** @noinspection ALL */
    public JComponent $$$getRootComponent$$$() {
        return root;
    }

}
